package com.hdd.art.biz.painting.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hdd.art.biz.painting.entity.WorkVerify;
import com.hdd.art.biz.painting.mapper.WorkVerifyMapper;
import com.hdd.art.biz.painting.service.WorkVerifyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdd.art.biz.show.entity.ArtShow;
import com.hdd.art.biz.show.service.ArtShowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fang
 * @since 2021-07-10
 */
@Service
public class WorkVerifyServiceImpl extends ServiceImpl<WorkVerifyMapper, WorkVerify> implements WorkVerifyService {

    @Autowired
    private ArtShowService artShowService;

    @Override
    public List<WorkVerify> getVerifyByWoriId(String workId){
        QueryWrapper<WorkVerify> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("work_id",workId);
        queryWrapper.orderByDesc("create_time");
        List<WorkVerify> list = baseMapper.selectList(queryWrapper);
        ArtShow artShow = null;
        for (WorkVerify verify:list){
            artShow =  artShowService.findArtShowById(verify.getArtId().toString());
            if(artShow!=null){
                verify.setArtImg(artShow.getLogoUrl());
            }
        }
        return list;
    }
    @Override
    public void contribute(String workId,String artId,Integer roomId,String userId){
        WorkVerify workVerify = new WorkVerify();
        workVerify.setWorkId(workId);
        workVerify.setArtId(artId);
        workVerify.setUserId(userId);
        workVerify.setRoomId(roomId);
        workVerify.setStatus(0);
        workVerify.setIsAdmin("F");
        baseMapper.insert(workVerify);
    }

    @Override
    public void updateStauts(Integer id,String workId,Integer stauts,String reason){
        WorkVerify workVerify = new WorkVerify();
        workVerify.setStatus(stauts);
        workVerify.setId(id);
        workVerify.setReason(reason);
        workVerify.setWorkId(workId);
        baseMapper.updateById(workVerify);
    }

    @Override
    public void delete(String artId, String workId) {
        QueryWrapper<WorkVerify> wrapper = new QueryWrapper<>();
        wrapper.eq("work_id",workId);
        wrapper.eq("aer_id",artId);
        baseMapper.delete(wrapper);
    }

    @Override
    public void insert(String workId, String artId, Integer stauts) {
        WorkVerify verify = new WorkVerify();
        verify.setWorkId(workId);
        verify.setArtId(artId);
        verify.setStatus(1);
        verify.setIsAdmin("T");
        baseMapper.insert(verify);
    }

    @Override
    public void updateRoom(String workId, Integer roomId) {
        WorkVerify verify = new WorkVerify();
        verify.setWorkId(workId);
        verify.setRoomId(roomId);
        QueryWrapper<WorkVerify> wrapper = new QueryWrapper<>();
        wrapper.eq("work_id",workId);
        baseMapper.update(verify,wrapper);
    }


}
